<template>
	<view class="shop_index">

		<view class="shop_header">
			<!-- <u-search shape="square" :showAction="false" bgColor="white" inputAlign="left" height="40"></u-search> -->
			<view @click="jumpSearch" class="index_search">
				<u-search bgColor="white" :showAction="false" placeholder="请输入关键字"></u-search>

			</view>

			<view class="index_banner">
				<u-swiper @click="test" height="160" keyName="item_banner_img" radius="12" :list="bannerList" indicator
					indicatorMode="line" circular></u-swiper>
			</view>
		</view>

		<view class="shop_main">
			<view class="shop_main_title">
				<text>手办推荐</text>
			</view>
			<view class="hot_list">
				<view class="hot_tab" v-for="item in this.hotList">
					<view class="tab_img" @click="jumpDetial(item.item_id)">
						<image :src="item.item_img" mode="aspectFill"></image>
					</view>

					<view class="tab_txt">
						<view class="txt_title">{{item.item_shops}}</view>
						<view class="txt_price">￥{{item.item_price}}</view>
					</view>
					<view class="hot_num"> <u-icon name="account" color="#c1c1c1" size="12"></u-icon>{{item.item_num}}
					</view>
				</view>

			</view>

			<!-- 	<view class="hot_list">
				<view class="hot_tab" v-for="item in 4">
					<view class="tab_img">
						<image src="/static/img/demo.webp" mode="aspectFill"></image>
					</view>
					<view class="tab_txt">
						<view class="txt_title">天青色等烟雨</view>
						<view class="txt_price">￥而我在等你</view>
					</view>
				</view>
			</view>
		 -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list3: [
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
				],
				hotList: [],
				bannerList: [],
				num: 0,
				allList: []
			}
		},
		onLoad() {

		},
		onReachBottom() {
			this.num++
			let newArr = this.allList.filter((item, index) => {
				return index >= this.num * 6 && index < (this.num + 1) * 6
			})
			this.hotList = this.hotList.concat(newArr)
			console.log(this.hotList)
		},
		async onShow() {
			uni.showLoading({
				title: "加载中..."
			})
			await uniCloud.callFunction({
				name: "select_shop",
				data: {

				}

			}).then((res) => {
				// this.hotList = res.result.data
				let newArr = res.result.data
				return newArr

			}).then((x) => {

				this.bannerList = x.filter((item) => {
					return item.item_banner_img != null
				})
				this.allList = x
				this.hotList = this.allList.filter((item, index) => {
					return index < 6
				})
				console.log(this.bannerList)
				console.log(this.hotList)
				uni.hideLoading()
			})
		},

		methods: {
			test(e) {
				// console.log(this.bannerList[e].item_id)
				let sid = this.bannerList[e].item_id
				uni.setStorageSync("sid", sid)
				uni.removeStorageSync("flat")
				uni.navigateTo({
					url: `/pages/detail/detail?sid=${sid}&flat=0`
				})

			},
			jumpDetial(sid) {
				console.log(sid);


				uni.setStorageSync("sid", sid)
				uni.removeStorageSync("flat")
				uni.navigateTo({
					url: `/pages/detail/detail?sid=${sid}&flat=0`
				})
			},
			jumpSearch() {
				console.log("收一下")
				uni.navigateTo({
					url: "/pages/search/search"
				})
			}
		}
	}
</script>

<style lang="scss">
	.hot_num {
		position: absolute;
		right: 10px;
		bottom: 10px;
		font-size: 12px;
		display: flex;
		color: #c1c1c1;
	}

	.index_banner {
		margin-top: 30rpx;
	}


	.shop_main_title {
		display: flex;
		justify-content: space-between;
		align-items: center;


	}

	.shop_main {
		margin: 40rpx 40rpx 0;
		font-size: 18px;


	}

	.hot_list {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;

		.hot_tab {
			background-color: white;
			height: 472rpx;
			width: 326rpx;
			margin-bottom: 20rpx;
			border-radius: 16px;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			overflow: hidden;
			position: relative;

			.tab_img {
				height: 364rpx;
				width: 100%;
				background-color: lightblue;
				box-sizing: border-box;
				border: 4px solid white;
				border-radius: 16px 16px 0 0;
				overflow: hidden;

				image {
					height: 100%;
					width: 100%;
				}
			}

			.tab_txt {
				border-top: 1px solid whitesmoke;
				height: 108rpx;
				width: 100%;
				background-color: white;

				.txt_title {
					margin-left: 20rpx;
					margin-top: 10rpx;
					font-size: 16px;
				}

				.txt_price {
					color: #ff78a2;
					margin-left: 20rpx;
					font-size: 14px;
				}
			}
		}
	}


	.shop_index {
		width: 100%;
		background-color: #f2f3f3;
		color: #333;

		.shop_header {
			margin: 0 20px;
			padding-top: 16px;

			.index_search {
				height: 90rpx;
				display: flex;
				justify-content: space-between;

				.inp {
					height: 100%;
					border-radius: 12px;
					background-color: white;
					line-height: 90rpx;
					width: 100%;
					display: flex;
					align-items: center;

					image {
						height: 40rpx;
						margin-left: 10px;
						width: 40rpx;
					}

					text {
						margin-left: 10px;
						font-size: 14px;
						color: #999;

					}
				}

			}
		}
	}
</style>